package com.jy.adscm.operation.mscyb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.mscyb.bean.JqbzAssembly;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqbzAssemblyMapper;
import com.jy.adscm.operation.mscyb.service.JqbzAssemblyService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-25
 */
@Service
public class JqbzAssemblyServiceImpl extends ServiceImpl<JqbzAssemblyMapper, JqbzAssembly> implements JqbzAssemblyService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<JqbzAssembly> selectByPid(String pid) {
        Wrapper<JqbzAssembly> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",pid);
        wrapper.orderBy("rank",false);
        List<JqbzAssembly> jqbzAssemblies = super.selectList(wrapper);
        for (JqbzAssembly jqbzAssembly : jqbzAssemblies) {
            JyUser jyUser = jyUserMapper.selectById(jqbzAssembly.getCreator());
            if (AdscmBaseUtils.getInstance().isNotEmpty(jyUser,null)){
                jqbzAssembly.setCreatorName(jyUser.getName());
            }
        }
        return jqbzAssemblies;
    }
}
